import moment from 'moment'
export function dealy(time = 1000) {
  return new Promise(res => {
    setTimeout(res, time)
  })
}

export function toLocaleDateString(time?: string | number | Date) {
  if (time) {
    return new Date(time).toLocaleDateString()
  }
  return ''
}

export function toLocaleString(time: string | number | Date) {
  if (time) {
    return new Date(time).toLocaleString()
  }
  return ''
}

export const MYDay = ['日', '一', '二', '三', '四', '五', '六']

export type ITimemyday = {
  D: number;
  M: number;
  W: string;
  Y: number;
  S: number;
  H: number;
}

export function Timemyday(): ITimemyday {
  const date = new Date
  return {
    D: date.getDate(),
    M: date.getMonth() + 1,
    W: MYDay[date.getDay()],
    Y: date.getFullYear(),
    S: date.getSeconds(),
    H: date.getHours(),

  }
}

// 返回 YYYY-MM-DD HH-MM
export function TimeYH(time: string | number | Date) {
  const data = new Date(time)
  return moment(data).format('YYYY-MM-DD HH:mm ')
}

export function tomoment(str: string, type?: string, totype?: string) {
  return moment(str, type).format(totype)
}
